# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/1 10:42
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : 元素的基本输入.py
# @Software : PyCharm
from selenium import webdriver
import time


# 元素的基本操作
def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('https://www.baidu.com/')

    # 模拟键盘的输入

    driver.find_element_by_id('kw').send_keys('lovelive superstar')

    # 模拟鼠标左键单击

    driver.find_element_by_id('su').click()
    time.sleep(2)

    # 获取元素text
    text1 = driver.find_element_by_xpath('//*[@id="1"]/div/h3/a').text
    print(text1)

    # 获取元素属性
    # get_attribute:适合于所有标签
    att = driver.find_element_by_xpath('//*[@id="1"]/div/h3/a').get_attribute('href')
    print(att)

    # 清空输入框
    # clear():只针对input标签,建议在每次输入前先clear，保证输入框为空
    driver.find_element_by_id('kw').clear()

    driver.find_element_by_id('kw').send_keys('世界尽头的骑士')
    driver.find_element_by_id('su').click()

    time.sleep(2)

    driver.quit()


if __name__ == '__main__':
    foo1()
